<template>
  <view>
    <nav-bar title="VIP定制服务"></nav-bar>
    <you-scroll
      :loadingHeight="loadingHeight"
      :mainHeight="scrollHeight"
      :isAllData="isAllData"
      :isRequestSuccess="isRequestSuccess"
      outPaddingTop="30rpx"
      @onRefresh="onRefresh"
      @loadMore="loadMore"
    >
      <template>
        <view v-if="isLoading" class="common-loading">
          <image class="loading-img" :src="baseIconUrl + '/commonIcon/icon_loading.png'" />
          正在加载数据，请稍后......
        </view>
        <view class="common-no-data" v-else-if="!customServeList || customServeList.length === 0">
          <image class="no-data-img" :src="baseIconUrl + '/commonIcon/icon_no_data.png'" />
          <view class="text">暂无数据</view>
        </view>
        <view v-else>
          <customServe-list :customServeList="customServeList"></customServe-list>
        </view>
      </template>
    </you-scroll>
  </view>
</template>

<script>
  import CustomServeList from '../../components/customServeList'
  import { baseImgUrl, baseIconUrl } from '@/config'
  import api_user from '@/api/user'
  export default {
    name: 'CustomServeList',
    components: { CustomServeList },
    data() {
      return {
        baseImgUrl,
        baseIconUrl,
        loadingHeight: '',
        scrollHeight: '',
        isAllData: false,
        isRequestSuccess: false,
        isLoading: false,
        pageNum: 1,
        pageSize: 10,
        total: 0,
        customServeList:[],
      }
    },
    onShow() {
      this.scrollHeight = this.$store.getters.heightData.noTabMainHeight + 'px'
      this.loadingHeight = this.$store.getters.heightData.noTabMainHeight - 20 + 'px'
      this.pageNum = 1
      this.customServeList = []
      this.getCustomServeList()
    },
    methods: {
      getCustomServeList() {
        const params = {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          cardType: 2
        }
        api_user.fetchCardRecordList(params).then(res => {
          if (res.code !== 200) return
          this.customServeList.push(...res.rows)
          this.total = res.total
          this.isRequestSuccess = true
          this.isLoading = false
        })
      },
      // 下拉刷新
      onRefresh() {
        this.pageNum = 1
        this.customServeList = []
        this.isAllData = false
        this.isRequestSuccess = false
        this.getCustomServeList()
      },
      // 上拉加载
      loadMore() {
        if (this.customServeList.length < this.total) {
          this.pageNum++
          this.isAllData = false
          this.isRequestSuccess = false
          this.getCustomServeList()
        } else {
          this.isAllData = true
        }
      }
    }
  }
</script>
<style lang="scss" scoped>

</style>
